CONTENTS | INDEX | PREV | NEXT
strnicmp
NAME
strnicmp - compare two strings up to a maximum number of characters
and case insensitive
SYNOPSIS
int r = strnicmp(s1, s2, n);
const char *s1;
const char *s2;
int n;
FUNCTION
Compares two strings, returning:
-1 s1 < s2
0 s1 == s2
1 s1 > s2
strnicmp differs from strcmp in that case is ignored for alphabetic
characters, i.e. a == A, and only up to n characters are compared.
Refer to stricmp() and strncmp() for other examples
NOTE
strnicmp() converts the chars in the string to unsigned quantities
when comparing them. However, for portability you should not
strnicmp() strings containing negative characters (bit 7 set) for
anything other than checking the result against 0. Use the
memcmp() routine instead.
EXAMPLE
#include <stdio.h>
#include <string.h>
#include <assert.h>
main()
{
char *s1 = "aBcAQ";
char *s2 = "abCDR";
char *s3 = "ABcXs";
char *s4 = "aBCDxX";
char *s5 = "aBC";
char *x2 = "AbCDt";
int r;
r = strnicmp(s2, x2, 4);
assert(r == 0);
r = strnicmp(s2, s1, 4);
assert(r > 0);
r = strnicmp(s2, s3, 4);
assert(r < 0);
r = strnicmp(s2, s4, 8);
assert(r < 0);
r = strnicmp(s2, s5, 4);
assert(r > 0);
return(0);
}
INPUTS
char *s1; pointer to first string
char *s2; pointer to second string
int n; maximum # of characters to compare
RESULTS
int r; result: -1, 0, or 1.
SEE ALSO
strcmp, strncmp, stricmp